<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.dao.CateDao" %>
<%@ page import="com.beans.CateInfo" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="css/edittable.css"/>
    <link rel="stylesheet" type="text/css" href="css/validate.css"/>
    <script type="text/javascript" src="js/jquery-1.8.0.js"></script>
    <script>
        $(function () {
            //验证分类名
            function validateCateName() {
                var result = true;
                var reg = /^\S{2,20}$/;   //2-20个合法字符(非空白)
                var cateName = $("#cateName").val();
                if (!reg.test(cateName)) {
                    result = false;
                    $("#cateName_msg").removeClass().addClass("validate_error").html("分类名称不合法");
                }
                if (result == true) {
                    $("#cateName_msg").removeClass().addClass("validate_ok").html("✓");
                }
                return result;
            }

            $("#cateName").focus(function () {
                $("#cateName_msg").removeClass().addClass("validate_info").html("长度2-20位");
            }).blur(function () {
                validateCateName();
            });
            //总验证
            $("#form_btn").click(function () {
                var result=true;
                if(validateCateName()==false){
                    result=false;
                }
                if($("#bigcateId").val()=="-1"){
                    result=false;
                    $("#bigcateId_msg").removeClass().addClass("validate_error").html("请选择一级分类");
                }
                if(result==true){
                    result=confirm('确定提交吗');
                }
                return result;
            });
        });
    </script>
</head>
<body>
<div class ="div_title">
    <div class="div_titlename"> <img src="${pageContext.request.contextPath }/images/san_jiao.gif" ><span>商品管理    二级分类维护</span></div>
</div>
<%
    //查询所有一级分类,构成一级分类下拉框
    CateDao dao=new CateDao();
    List<CateInfo> cateList=dao.getCateList(0);
    request.setAttribute("cateList",cateList);

    int cateId=Integer.parseInt(request.getParameter("id"));
    CateInfo  cateInfo=dao.getCateListById(cateId);
    request.setAttribute("cateInfo",cateInfo);
%>
<form action="CateServlet.do" method="post">
    <input name="flag" value="updateSmallCate" type="hidden">
    <input type="hidden" name="id" value="${cateInfo.id}">
<table class="edit_table" >
    <tr>
        <td class="td_info">父级分类:</td>
        <td class="td_input_short">
            <select  class="txtbox" name="bigCateId" id="bigCateId">
                <c:forEach var="cate" items="${cateList}">
                    <option <c:if test="${cate.id==cateInfo.parentId }">selected</c:if> value="${cate.id}">${cate.cateName}</option>
                </c:forEach>
            </select>
        </td>

    </tr>

    <tr>
        <td class="td_info">分类名称:</td>
        <td  class="td_input_short">
            <input type="text" class="txtbox" id="cateName" name="cateName" value="${cateInfo.cateName }"
            />
        </td>
        <td>
            <label class="validate_info" id="cateName_msg">长度 2-20 位非空白字符</label>
        </td>
    </tr>

    <tr>
        <td class="td_info">分类描述:</td>
        <td  class="td_input_short"><textarea rows="4" cols="27" name="des" class="txtarea">${cateInfo.des}</textarea> </td>
        <td><label></label></td>
    </tr>
    <tr>
        <td class="td_info"> </td>
        <td  class="td_input_short">
            <input class="form_btn" type="submit" id="form_btn" value="保存修改" />
        <td>
            <label id="result_msg" class="result_msg">${msg}</label>
        </td>
    </tr>
</table>
</form>
</body>
</html>
